"""绝对领域，二次元爬取"""

import parsel
import requests

url = "https://www.jdlingyu.com/collection/acg"
base_dir = "E:\\T\\Picture\\jdlingyu\\动漫\\"
res = requests.get(url)
html = res.text
selector = parsel.Selector(html)
# 获取相册列表的定位方式
pics_list = selector.css('h2>a')
for i in pics_list:
    # 输出相应提示信息
    title = i.css("::text").get().split()[1]
    print(f"-----------{title}-----------")
    href = i.css("::attr(href)").get()
    resp = requests.get(href).text
    select = parsel.Selector(resp)
    pics = select.css('p>img::attr(src)').getall()
    # print(pics)
    for j in pics:
        name = j.split('/')[-1]
        print(name)
        data = requests.get(j).content
        with open(base_dir + name, "wb") as f:
            f.write(data)
